package net.deuce.perf;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SimpleStats implements Comparable {
    private long maxTime = 0;
    private long minTime = Long.MAX_VALUE;
    private long totalTime = 0;
    private long count = 0;
    private String name;
    private Log log = LogFactory.getLog(getClass());

    public SimpleStats(String name) {
        //log.trace("");
        this.name = name;
    }

    public long getMaxTime() {
        //log.trace("");
        return maxTime;
    }

    public void setMaxTime(long maxTime) {
        //log.trace("");
        this.maxTime = maxTime;
    }

    public long getMinTime() {
        //log.trace("");
        return minTime;
    }

    public void setMinTime(long minTime) {
        //log.trace("");
        this.minTime = minTime;
    }

    public double getAvgTime() {
        //log.trace("");
        return (double)totalTime/(double)count;
    }

    public void addTime(long t) {
        //log.trace("");
        totalTime += t;
        count++;
    }

    public String getName() {
        //log.trace("");
        return name;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SimpleStats that = (SimpleStats) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    public int hashCode() {
        return name.hashCode();
    }

    public int compareTo(Object o) {
        if (!(o instanceof SimpleStats)) return -1;
        SimpleStats that = (SimpleStats)o;

        if (this.getAvgTime() > that.getAvgTime()) return -1;
        if (this.getAvgTime() < that.getAvgTime()) return 1;
        return 0;
    }
}
